import 'package:flutter/material.dart';
import 'package:flutter_base_study/routers/form_page.dart';
import 'package:flutter_base_study/routers/news_page.dart';
import 'package:flutter_base_study/tools/routers.dart';
import 'package:flutter_base_study/routers/search_page.dart';
import 'package:flutter_base_study/routers/shoppage.dart';
import 'package:flutter_base_study/scaffold/page/home.dart';
import 'package:flutter_base_study/scaffold/tabs.dart';
import 'package:flutter_base_study/scaffold/tabbar_tabbarview_demo.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  ///--1、定义Map类型的routes
  Map routes = {
    //命名路由传值
    '/form_page': (context, {arguments}) => FormPage(arguments: arguments),
    "/shop":(context,{arguments})=> ShopPage(arguments: arguments),
    '/home': (context) => const Home(),
    '/news_page': (context) => const NewsPage(),
    '/search_page': (context) {
      return SearchPage();
    },
    '/tabbar_tabbarview_demo': (context) => const TabBarViewDemo(),
    '/': (context) => const Tabs(),
  };

  MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    ///Getx状态管理
    return GetMaterialApp(
      // return MaterialApp(
      title: 'Flutter Demo',
      // theme: ThemeData(
      //   colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      //   useMaterial3: true,
      // ),
      // home: const MyHomePage(title: 'Flutter Demo Home Page'),

      ///----------配置主题------------
      //主题2
      theme: ThemeData.light(),
      //主题1：夜间模式
      // theme: ThemeData.dark(),
      //主题3
      // theme: ThemeData(
      //   colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple)
      // ),
      //主题4
      // theme: ThemeData(
      //   colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      //   useMaterial3: true,
      // ),
      //主题5 useMaterial3夜间模式
      // theme: ThemeData(
      //   colorScheme: ColorScheme.dark(),
      //   useMaterial3: true,
      // ),
      ///----------配置主题------------

      ///去掉debug图标
      debugShowCheckedModeBanner: false,

      ///---------命名路由-----------
      // //初始化路由 (默认跳转的界面)
      initialRoute: '/',
      // //命名路由  配置
      // //map类型对象
      // routes: {
      //   '/main': (context) => const MyApp(),
      //   '/home': (context) => const Home(),
      //   '/form_page': (context) => const FormPage(),
      //   '/news_page': (context) => const NewsPage(),
      //   '/search_page': (context) {
      //     return SearchPage();
      //   },
      //   '/tabbar_tabbarview_demo': (context) => const TabBarViewDemo(),
      //   '/': (context) => const ScaffoldWidget(),
      // },

      ///--2、调用onGenerateRoute处理 固定写法(已封装)
      onGenerateRoute: onGenerateRoute,
      // onGenerateRoute: (RouteSettings settings) {
      //   //命名路由名城
      //   final String? name = settings.name;
      //   final Function? pageContentBuilder = routes[name];
      //   if (pageContentBuilder != null) {
      //     if (settings.arguments != null) {
      //       final Route route = MaterialPageRoute(
      //           builder: (context) =>
      //               pageContentBuilder(context, arguments: settings.arguments));
      //       return route;
      //       // 26.5.2、定义页面接收
      //       // arguments传参
      //       // 26.5.3、跳转页面实现传参
      //     } else {
      //       final Route route = MaterialPageRoute(
      //           builder: (context) => pageContentBuilder(context));
      //       return route;
      //     }
      //   }
      //   return null;
      // },

      ///---------命名路由-----------

      ///Scaffold 与 Text控件
      // home: TestWidget(),

      ///图片样式
      // home: ImageWidget(),

      ///三种布局
      // home: LayoutWidget(),
      ///Button
      // home: ButtonWidget(),

      ///StateFulWidget和setState
      // home: StateFulWidget(),
      // home: StatefulWidgetListDemo(),
      ///Color
      // home: ColorWidget(),
      ///Container布局
      // home: ContainerWidget(),
      ///GestureDetector手势
      // home: GestureDetectorWidget(),
      ///输入框
      // home: TExtFieldWidget(),
      ///列表 listview 普通，用于设置中的相同布局
      // home: ListWidget01(),
      ///ListView.builder
      // home: ListWidget04(),
      ///dialog
      // home: DialogDemo(),
      ///跳转与生命周期
      // home: Page01(),
      ///Scaffolf
      //home: const ScaffoldWidget(),
      // home: TabBarViewDemo(),

      ///sqlite3 demo
      // home: SqliteDemo(),
      ///生命周期
      // home: StatelessDemo(title: "QQQQ"),
      // home: StatefulDemo(title: "FFFFF"),

      ///数据共享 InheritedWidget
      // home: const InheritedDemo(),
      ///key demo
      // home: KeyDemo(),
      ///globalkey
      // home: GlobalKeyDmeo(),
      //MaterialApp
      // home: MaterialAppDemo(),
      //stack
      // home: StackDemo(),
      ///宽高比  aspectration
      // home: AspectRatioDemo(),
      ///row横向
      // home: RowDemo(),
      ///灵活布局，自动拉升
      // home: ExpandedDemo(),
      ///流式布局Wrap
      // home: WrapDemo(),
      ///流式布局热搜  wrap
      // home: WrapDemoHotsearch(),
      ///子组件按比例显示
      // home: AspectRatioDemo(),
      ///通讯录卡片
      // home: CardDemo(),
      // home: CardImageDemo(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          //
          // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
          // action in the IDE, or press "p" in the console), to see the
          // wireframe for each widget.
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
